package com.witherest.server.controller.api;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import com.witherest.server.common.bean.ResponseCode;
import com.witherest.server.vo.response.CommonResponse;
import com.witherest.server.vo.response.LoginResponse;

@Controller
@RequestMapping("/{requestType}")
public class LoginController {
	private static final Logger logger = LoggerFactory.getLogger(LoginController.class);
	
	/**
	 * 로그인 처리
	 *
	 * @param userId the user id
	 * @param userPw the user pw
	 * @return the common response
	 * @throws Exception the exception
	 */
	@RequestMapping(value = "/login", method = RequestMethod.POST)
	@ResponseBody
	public LoginResponse login( @PathVariable String requestType,
                                @RequestParam String userId,
                                @RequestParam String userPw,
                                @RequestParam String gcmId) throws Exception {
		logger.debug("Login API(userId = {}, userPw = {}, gcmId = {}", new String[] {userId, userPw, gcmId});
		
		LoginResponse result = new LoginResponse(ResponseCode.SUCCESS);
		result.setToken("sample_token");
        result.setRequestType(requestType);
		
		return result;
	}
	
	/**
	 * 로그아웃 처리
	 *
	 * @param token the token
	 * @return the common response
	 * @throws Exception the exception
	 */
	@RequestMapping(value = "/logout", method = RequestMethod.DELETE)
	@ResponseBody
	public CommonResponse logout(@PathVariable String requestType, @RequestHeader String token) throws Exception {
		logger.debug("Logout API(token = {}", token);

        CommonResponse cr = new CommonResponse(ResponseCode.SUCCESS);
        cr.setRequestType(requestType);
		return cr;
	}
}
